package alg20241128;

public class Text2 {
    public static void main(String[] args) {

    }
    public  String countAndSay(int n) {
        String ret = "1";
        if(n == 1) return ret;
        for (int i = 1; i < n; i++) {
            StringBuilder tmp = new StringBuilder();
            for (int left = 0, right = 0; right < ret.length();) {
                while(right < ret.length() && ret.charAt(left) == ret.charAt(right)) right++;
                tmp.append(Integer.toString(right - left));
                tmp.append(ret.charAt(left));
                left = right;
            }
            ret = tmp.toString();
        }
        return ret;

    }
}
